package com.anda.logistics.dao.impl;

import org.springframework.stereotype.Component;

import com.anda.logistics.dao.FreightDeliverDao;
import com.anda.logistics.model.FreightDeliver;
@Component
public class FreightDeliverDaoImpl extends AndaBaseSuperDao implements
		FreightDeliverDao {

	@Override
	public void save(FreightDeliver freightDeliver) {
		sessionFactory.getCurrentSession().save(freightDeliver);
	}
	@Override
	public void update(FreightDeliver freightDeliver) {
		sessionFactory.getCurrentSession().update(freightDeliver);
	}

	@Override
	public FreightDeliver getOnRoadOneByTruckId(long truckId) {
		return (FreightDeliver) sessionFactory.getCurrentSession()
			.createQuery("from FreightDeliver where truckId = :truckId and freightState = 2 ")
			.setLong("truckId", truckId)
			.setMaxResults(1)
			.uniqueResult();
	}
	@Override
	public FreightDeliver getOnRoadOneByFreightId(long freightId) {
		return (FreightDeliver) sessionFactory.getCurrentSession()
				.createQuery("from FreightDeliver where freightId = :freightId and freightState = 2 ")
				.setLong("freightId", freightId)
				.setMaxResults(1)
				.uniqueResult();
	}
	
}
